﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

namespace SNSpirit.Documents.Adatpers.Ubb
{
	using Snowdreamist.Text.UBB;
	using Snowdreamist.Windows.Document;

	using Internal;

	/// <summary>
	/// Document adapter which converts UBB Code to Rich Text Document.
	/// </summary>
	public class UbbToRichTextAdapter : ITypedDocumentAdapter
	{
		/// <summary>
		/// Get or set the conversion options.
		/// </summary>
		public UbbToRichTextOptions Options
		{
			get;
			set;
		}

		public RichTextDocument Convert(UBBDocument source)
		{
			if (source == null)
			{
				throw new ArgumentNullException("source");
			}

			// Need for code contracts.
			Contract.EndContractBlock();

			return UbbToRichTextService.Convert(source, this.Options);
		}

		object ITypedDocumentAdapter.Convert(TypedDocument source, string targetType)
		{
			if (targetType == KnownContentTypes.RichTextDocument && source.ContentType == KnownContentTypes.Ubb)
			{
				return UbbToRichTextService.Convert(source.Content as UBBDocument, this.Options);
			}

			else
			{
				// Todo: Consider to return null for stability reason.
				throw new NotSupportedException();
			}
			
		}
	}
}
